package com.wys.mall.order.controller;

import com.alibaba.nacos.common.utils.UuidUtils;
import com.wys.mall.order.entity.OrderEntity;
import com.wys.mall.order.entity.OrderItemEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Package com.wys.mall.order.controller
 * @Author charlin
 * @Version: v1.0
 * @Date 2021-07-1012:01
 * @Copyright: 2021 www.wyscha.com Inc. All rights reserved.
 */
@RestController
public class RabbitController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendMq")
    public String sendMq(@RequestParam(value = "num", defaultValue = "10") Integer num){
        for (int i = 0; i < num ; i++) {
            if(i % 2== 0){
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setBillContent("aaaaaaaa--" + i);
                orderEntity.setAutoConfirmDay(i);
                orderEntity.setBillHeader("kkkk--" + i);
                rabbitTemplate.convertAndSend("exchange.first.direct", "queue.first", orderEntity);
            }else {
                OrderItemEntity itemEntity = new OrderItemEntity();
                itemEntity.setOrderSn(UuidUtils.generateUuid().toString());
                rabbitTemplate.convertAndSend("exchange.first.direct", "queue.first", itemEntity);
            }
        }
        return "sucess";
    }
}
